import {createStore} from 'redux';

// const Reducer = (state={username:'haha'}, action) => {
//   console.log("改变前store",state)
//   console.log("将要改变的action",action)
//   switch(action.type) {
//     case "CHANGE_USER":
//       return {
//         username: action.date,
//       };
//   }
//   return state;
// }

const Reducer = function (state = { 
  username: document.cookie?.split(';')[0]?.split('=')[1],
  id: document.cookie?.split(';')[1]?.split('=')[1]
}, action) {

  switch (action.type) {
    case 'CHANGE_USER':
      return { 
        ...state,
        username: action.data
      };
    case 'CHANGE_ID':
      return {
        ...state,
        id: action.data
      }
    default:
      return state
  }
}


const store = createStore(Reducer);

export default store;
